package com.jbp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jbp.dao.PrizePoolAmountDao;
import com.jbp.model.PrizePoolAmount;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class PrizePoolAmountService extends ServiceImpl<PrizePoolAmountDao, PrizePoolAmount> implements IService<PrizePoolAmount> {


    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PrizePoolAmount> queryWrapper = new QueryWrapper<>();
        if (params.get("id") != null) {
            queryWrapper.like("id",params.get("id"));
        }
        if (params.get("amount") != null) {
            queryWrapper.like("amount",params.get("amount"));
        }
        if (params.get("createTime") != null) {
            queryWrapper.like("create_time",params.get("createTime"));
        }
        if (params.get("endTime") != null) {
            queryWrapper.like("end_time",params.get("endTime"));
        }
        if (params.get("flag") != null) {
            queryWrapper.like("flag",params.get("flag"));
        }
        if (params.get("fromDate")!=null) {
            queryWrapper.ge("create_time", params.get("fromDate"));
        }
        if (params.get("toDate")!=null) {
            queryWrapper.le("DATE_FORMAT(create_time,   '%Y-%m-%d')", params.get("toDate"));
        }
        queryWrapper.orderByDesc("id");
        IPage<PrizePoolAmount> page = this.page(
            new Query<PrizePoolAmount>().getPage(params), queryWrapper
        );
        return new PageUtils(page);
    }
}
